package com.itbaizhan.springbootdemo4.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
/*注册Web组件——Filter（过虑器）
* 方式一：
* 1,编写filter，在类上加注解@WebFilter()
* 2, 2,在启动类上添加@servletComponentScan (SpringBoot启动时扫描注册解标注的web组件)*/

//过虑的路径是/first
@WebFilter(urlPatterns = "/first")
public class FirstFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("进入first filter");
        //放行
        filterChain.doFilter(servletRequest,servletResponse);
        System.out.println("结束first filter");
    }

    @Override
    public void destroy() {

    }
}
